

<template>
    <div>
        <el-button class="butB_Sel" @click="printBtn()">打印</el-button>
        <el-button class="butB_Sel" @click="printBtn2()">CLodop打印</el-button>
        <div class="app-container" id="printcons">
            <table border="0" width="90%" align="center" >
                <thead>
                    <tr style="line-height: 60pt; text-align: center">
                        <td colspan="4" style="font-size: 26px" class="titleB">
                            {{ his_name }}处方笺
                        </td>
                    </tr>
                    <tr style="border-bottom: 1px solid black;" colspan="4">
                        <td>科室：{{ params.masterInfo.department_name }}</td>
                        <td>费用：{{ params.multipleSelection[0].fee_category_name }}</td>
                        <td colspan="2">时间：{{ params.multipleSelection[0].created_at }}</td>
                    </tr>
                    <tr>
                        <td>姓名：{{ params.member.name }}</td>
                        <td>性别：{{ params.gender == 1 ? '男' : '女' }}</td>
                        <td>年龄：{{ params.member.age }}</td>
                        <td>住院号：{{ params.masterInfo.ipt_no }}</td>
                    </tr>
                    <tr>
                        <td style="border-bottom: 1px solid black;" colspan="4">临床诊断：{{
                                params.masterInfo.disease[0].disease_name
                        }}</td>

                    </tr>

                </thead>
                <tbody>
                    <tr>
                        <td colspan="4" style="font-size:30px">R:</td>
                    </tr>
                    <template v-for="(item, index) in params.multipleSelection">
                        <tr>
                            <td>{{ item.business_name }}</td>
                            <td>{{ item.specification }}</td>
                            <td>{{ item.number }} {{ item.unit }}</td>
                            <td>{{ item.total }}</td>
                        </tr>
                        <tr>
                            <td colspan="4">用法：{{ item.usage }}</td>
                        </tr>
                    </template>

                </tbody>
                <tfoot class="footer" borderthin="true">
                    <tr>
                        <td colspan="4" style="border-bottom: 1px solid black;">备注：</td>

                    </tr>
                    <tr>
                        <td>医师：</td>
                        <td>药价：</td>
                        <td colspan="2">其它：</td>
                    </tr>
                    <tr>
                        <td>调剂：</td>
                        <td>核对、发药:</td>
                        <td colspan="2">取药：</td>
                    </tr>
                    <tr>
                        <td colspan="4">备注：该处方及申请单仅限当日当次使用:谢谢配合</td>

                    </tr>

                </tfoot>
            </table>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            tabeldata: {},
            sourcelist: [],
            style2: {
                width: "800px",
                padding: "0px 40px",
                marginTop: "0",
                height: "1150px",
                fontSize: "20px",
                paddingTop: "40px",
            },
            drug2: [],
            fee_category_name: "",
            dayin: false,
            his_name: process.env.VUE_APP_HOSPITAL_API2,
            params: {},
            dept_info_name: "",
        };
    },

    mounted() {
        this.drug2 = [];
        this.params = JSON.parse(this.$route.query.params);
        console.log("params", this.params)
        //   this.dept_info_name =
        //     this.params.dept_info == undefined
        //       ? this.params.dept_name
        //       : this.params.dept_info.name;

        //   console.log(this.$route.query.params);
        //   this.his_name = process.env.VUE_APP_HOSPITAL_API2;
        //   var arr = this.params.drug;
        //   if (this.params.drug.length > 5) {
        //     for (let i = 0; i < Math.ceil(arr.length / 5); i++) {
        //       this.drug2.push(arr.slice(i * 5, 5 * (i + 1)));
        //     }
        //     console.log(this.drug2);
        //   } else {
        //     this.drug2.push(arr);
        //   }
        //   this.fee_category_name = this.drug2[0][0].drug.fee_category.name;
    },
    //  watch: {

    //   params(n) {
    //     this.drug2=[]
    // 	console.log(n.drug,'进入')
    //     var arr=n.drug
    //    if(arr.length>5){

    //     for (let i = 0; i < Math.ceil(arr.length/5); i++) {
    //    this.drug2.push(arr.slice(i*5,5*(i+1)));
    //      this.fee_category_name=this.drug2[0][0].drug.fee_category.name
    //   }

    //   }else{

    //     this.drug2.push(arr)
    //   }
    //      console.log(this.drug2,'1111111')
    //      this.fee_category_name=this.drug2[0][0].drug.fee_category.name
    // },

    //   },

    methods: {
        getindex() {
            getdictIndex({ group_id: "40" }).then((res) => {
                let data = res.data;
                data.forEach((item, key) => {
                    if (item.id == 40) {
                        this.sourcelist = item.items;
                    }
                });
            });
        },
        getpint() {
            this["_API"].getPrintReport({ id: this.id }).then((res) => {
                if (res.code == 200) {
                    this.tabeldata = res.data;
                    this.tabeldata.source = this.mapxing(this.tabeldata.source);
                }
            });
        },

        mapxing(num) {
            var art = "";
            this.sourcelist.map(function (value, i, array) {
                if (value.id == num) {
                    art = value.name;
                }
            });
            console.log(art);
            return art;
        },
        printBtn2() {
            this.LODOP = getLodop();
            let strTableStyle = `<style>
                                    thead td,tfoot td {
                                        border: 0;
                                       
                                        padding: 0;
                                        margin: 0;
                                        padding: 10px 0;
                                    }
                                    tbody td{
                                        padding:10px 0
                                    }
                                    td {
                                        margin: 0;
                                        padding: 0;
                                        border: 0;
                                        font-size: 20px;
                                    }
                                    </style>`
            this.LODOP.ADD_PRINT_TABLE(
                0,
                0,
                "100%",
                "100%",
                strTableStyle + `<body>` +document.getElementById("printcons").innerHTML + `</body>`,
            );
            this.LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "100%");
            this.LODOP.SET_PRINT_STYLEA(0, "LinkedItem", -1);
            this.LODOP.PREVIEW();
        },

        printBtn(e) {
            this.dayin = true;

            setTimeout(() => {
                this.dayinfun();
            }, 200);
        },
        dayinfun() {
            this.remove_ie_header_and_footer();
            let subOutputRankPrint = document.getElementById("printcons");
            console.log(subOutputRankPrint.innerHTML);
            let newContent = subOutputRankPrint.innerHTML;
            let oldContent = document.body.innerHTML;
            document.body.innerHTML = newContent;
            window.print();
            // window.location.reload();
            // window.open("", "_self").close(), (document.body.innerHTML = oldContent);
            return false;
        },
        //去掉页眉和页脚
        remove_ie_header_and_footer() {
            var hkey_path;
            hkey_path =
                "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
            try {
                var RegWsh = new ActiveXObject("WScript.Shell");
                RegWsh.RegWrite(hkey_path + "header", "");
                RegWsh.RegWrite(hkey_path + "footer", "");
            } catch (e) { }
        },
    },
};
</script>
<style  media="print">

    thead td {
        border: 0;
        padding: 0;
        margin: 0;
        padding: 10px 0;
    }
    tfoot td {
       
        padding: 10px 0;
    }
    tbody td{
        padding:10px 0
    }
   
    td {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 20px;
    }
</style>
<style lang='scss' scoped>
#printcons {
    margin: auto;
    box-sizing: border-box;
    width: 60%;

    thead td{

        border: 0;
        // border-bottom: 1px solid black;
        padding: 0;
        margin: 0;
        padding: 10px 0;
    }
    tfoot td {
       
       padding: 10px 0;
   }
   tbody{
    padding-bottom:50px
   }
    tbody td{
        padding:10px 0
    }
   
    td {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 20px;
    }
}
</style>